
#include <Liberty3D/Library/Mutex/Local.h>

#include <boost/smart_ptr/detail/spinlock.hpp>
#include <boost/thread/locks.hpp>

using namespace Liberty::Library;
using namespace Liberty::Library::Mutex::Impl::Local;

Liberty::Library::Mutex::Impl::Local::Mutex::Mutex() {
}

IExclusiveLock* Liberty::Library::Mutex::Impl::Local::Mutex::lock() {
    return new Lock(_mutex);
}

SharedMutex::SharedMutex() {
}

IExclusiveLock* SharedMutex::lock() {
    return new UniqueLock(_mutex);
}

ISharedLock* SharedMutex::lockShared() {
    return new SharedLock(_mutex);
}

SharedLock::SharedLock(boost::shared_mutex& mutex) : _guard(mutex) {
}

IExclusiveLock* SharedLock::upgrade() {
    return new UpgradedLock(_guard);
}

Liberty::Library::Mutex::Impl::Local::Lock::Lock(boost::mutex& mutex) : _guard(mutex) {
}

UpgradedLock::UpgradedLock(boost::upgrade_lock<boost::shared_mutex>& guard) : _guard(guard) {
}

UniqueLock::UniqueLock(boost::shared_mutex& mutex) : _guard(mutex) {
}
